package com.yingma.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yingma.system.dao.JcSysOrganizationDao;
import com.yingma.system.entity.JcVehicle;
import com.yingma.system.entity.JcVehicleHead;
import com.yingma.system.dao.JcVehicleHeadDao;
import com.yingma.system.service.JcVehicleHeadService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (JcVehicleHead)表服务实现类
 *
 * @author makejava
 * @since 2020-04-02 14:56:47
 */
@Service("jcVehicleHeadService")
public class JcVehicleHeadServiceImpl implements JcVehicleHeadService {
    @Resource
    private JcVehicleHeadDao jcVehicleHeadDao;

    @Resource
    private JcSysOrganizationDao jcSysOrganizationDao;
    /**
     * 根据条件查询车头信息
     * @param code
     * @param pageNum
     * @param PageSize
     * @return
     */
    @Override
    public List<JcVehicleHead> queryby(String code, Integer pageNum, Integer PageSize) {
        List<JcVehicleHead> list=null;
        QueryWrapper<JcVehicleHead> queryWrapper=new QueryWrapper<JcVehicleHead>();
        if(!code.equals("")&&code!=""){
            queryWrapper.like("CODE",code);
        }

        Page<JcVehicleHead> page=new Page<>(pageNum,PageSize,true);
        IPage<JcVehicleHead> iPages=jcVehicleHeadDao.selectPage(page,queryWrapper);
        list=iPages.getRecords();
        for(int i=0;i<list.size();i++){
            list.get(i).setJcSysOrganization(jcSysOrganizationDao.selectById(list.get(i).getJcOrganizationId()));
        }
        if(list.size()>0){
            list.get(0).setTotalpageNum(new Long(iPages.getPages()).intValue());
            list.get(0).setTotalSize(new Long(iPages.getTotal()).intValue());
        }
        return list;
    }
}
